﻿#include "mainscene.h"
#include "ui_mainscene.h"
#include<QPainter>
#include<QDebug>
#include<mypushbutton.h>
#include<QTimer>
#include<QSound>
#pragma execution_character_set("utf-8")
MainScene::MainScene(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainScene)
{
    ui->setupUi(this);
    //配置主场景

    //配置固定大小
    setFixedSize(320,588);

    //设置图标
    setWindowIcon(QIcon(":/res/Coin0001.png"));
    //设置标题
    setWindowTitle("地主带你翻金币");

    //实现菜单栏下的退出功能
    connect(ui->actionquit,&QAction::triggered,[=](){
        this->close();
    });

    //准备开始按钮音效
    QSound * startSound = new QSound(":/res/TapButtonSound.wav");

    //开始按钮
    MyPushButton * startBtn =
            new MyPushButton(":/res/MenuSceneStartButton.png");
    startBtn->setParent(this);
    startBtn->move(this->width()*0.5-startBtn->width()*0.5,this->height()*0.7);

    //实例化选择关卡场景
    chooseScene = new ChooseLevelScene;


    //监听选择关卡的返回按钮的信号
    connect(chooseScene,&ChooseLevelScene::chooseSceneBack,this,[=](){
        chooseScene->hide();//选择关卡场景隐藏掉
        this->show();//重新显示主场景
    });






    connect(startBtn,&MyPushButton::clicked,[=](){
//        qDebug() << "点击了开始";
        //播放开始音效资源
        startSound->play();
        //做一个弹起的 特效
        startBtn->zoom1();
        startBtn->zoom2();

        //延时进入到选择关卡场景中
        QTimer::singleShot(500,this,[=]{
            //设置chooseScene场景的位置
            chooseScene->setGeometry(this->geometry());

            //自身影藏
            this->hide();
            //进入到选择关卡的场景中
            chooseScene->show();


        });

    });





}

MainScene::~MainScene()
{
    delete ui;
}

//绘图事件
void MainScene::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/PlayLevelSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);

    //画背景上图标
    pix.load(":/res/Title.png");
    //觉得图标太大，缩放图标
    pix = pix.scaled(pix.width()*0.5,pix.height()*0.5);
    painter.drawPixmap(10,30,pix);



}

